const Joi = require('joi');

class ProductValidate {

  async insert(param) {
    const schema = Joi.object({
      order_id: Joi.string()
        .require()
        .messages({
          'string.required': '订单id是必填项',
          'string.empty': '订单id不能为空',
        }),

      products: Joi.array().items(
        Joi.string().required().messages({
          'string.required': '产品id是必填项',
          'string.empty': '产品id不能为空',
        })
      ),
    });

    try {
      const value = await schema.validateAsync(param);

      return value;
    } catch (error) {
      throw error;
    }
  }

  async product(param) {
    const schema = Joi.object({
      uuid: Joi.string()
        .required()
        .messages({
          'string.required': 'uuid是必填项',
          'string.empty': 'uiid不能为空',
        }),

      order: Joi.string(),

      method: Joi.string(),

      pageIndex: Joi.string(),

      pageSize: Joi.string(),
    });

    try {
      const value = await schema.validateAsync(param);

      return value;
    } catch (error) {
      throw error;
    }
  }
}

module.exports = new ProductValidate();
